package com.huaxin.hxmoduleworkorder.event;

import java.time.Instant;

/**
 * 检查项变更事件
 * 不可变对象，用于通知系统检查项已变更
 */
public final class InspectionOrderItemChangeEvent {
    /**
     * 巡查工单ID
     */
    private final String orderId;

    /**
     * 客户ID
     */
    private final String customerId;

    /**
     * 事件类型
     */
    private final EventType eventType;

    private final Instant timestamp;

    // 私有构造，仅允许通过静态工厂创建
    private InspectionOrderItemChangeEvent(String orderId,
                                           String customerId,
                                           EventType eventType,
                                           Instant timestamp) {
        this.orderId = orderId;
        this.customerId = customerId;
        this.eventType = eventType;
        this.timestamp = timestamp;
    }

    // ---------------- 静态工厂方法 ----------------

    public static InspectionOrderItemChangeEvent created(String orderId, String customerId) {
        return new InspectionOrderItemChangeEvent(orderId, customerId, EventType.CREATED, Instant.now());
    }

    public static InspectionOrderItemChangeEvent updated(String orderId, String customerId) {
        return new InspectionOrderItemChangeEvent(orderId, customerId, EventType.UPDATED, Instant.now());
    }

    public static InspectionOrderItemChangeEvent deleted(String orderId, String customerId) {
        return new InspectionOrderItemChangeEvent(orderId, customerId, EventType.DELETED, Instant.now());
    }

    // ---------------- Getter ----------------

    public String getOrderId() {
        return orderId;
    }

    public String getCustomerId() {
        return customerId;
    }

    public EventType getEventType() {
        return eventType;
    }

    public Instant getTimestamp() {
        return timestamp;
    }

    @Override
    public String toString() {
        return "InspectionOrderItemChangeEvent{" +
                "orderId='" + orderId + '\'' +
                ", customerId='" + customerId + '\'' +
                ", eventType=" + eventType +
                ", timestamp=" + timestamp +
                '}';
    }
}

/**
 * 事件类型枚举
 */
enum EventType {
    CREATED,
    UPDATED,
    DELETED
}
